<template>
    <div class="detail" ref="detail" >
        <detail-header :headData="headerData"></detail-header>
        <detail-package ref='package' :packageList="packageList"></detail-package>
        <detail-actinfo></detail-actinfo>
        <detail-profile></detail-profile>
        <detail-interact></detail-interact>
        <detail-masker></detail-masker>
        <detail-signupstep :packageList="packageList"></detail-signupstep>
        <detail-bottom @moveregister="handleToRegister" :propsBottom="propsBottom"></detail-bottom>
        <div v-wechat-title="$route.meta.title"></div>
    </div>
</template>

<script>
import DetailHeader from './components/Header'
import DetailPackage from './components/Package'
import DetailActinfo from './components/ActInfo'
import DetailProfile from './components/Profile'
import DetailInteract from './components/Interact'
import DetailBottom from './components/Bottom'
import DetailMasker from './components/Masker'
import DetailSignupstep from './components/Signupstep'
import BScroll from 'better-scroll'
import { mapMutations } from 'vuex'
import axios from 'axios'

export default {
    name: 'Detail',
    components: {
        DetailHeader,
        DetailPackage,
        DetailActinfo,
        DetailProfile,
        DetailInteract,
        DetailBottom,
        DetailMasker,
        DetailSignupstep
    },
    created () { 
        const detailId = this.$route.params.id
        //先判断用户和该活动有没有关系
        //  1.用户已经报名该活动
        //  2.用户评价过该活动
        // if(detailId == '001') {
        //     this.propsBottom.hadRegister = 1
        // }
        let _this = this
        axios.get('http://wxx.qipigou.com/api/Activity/getActOne', {
                params: {
                    detailId: detailId
                }
            })
            .then(function (response) {
                const data = response.data.data
                _this.handleGetHeaderData(data)
                _this.packageList = data.product
            })
         
    },
    mounted () {
        
    },
    data () {
        return {
            maskerType : 0,
            headerData: null, 
            packageList: null,
            propsBottom: {
                hadRegister: 0
            }
        }
    },
    methods: {
        handleToRegister () {
            const offsetTop = this.$refs['package'].$el.offsetTop
            window.scrollTo(0, offsetTop)
        },
        ...mapMutations([
            'change_Detail_MaskerType',
            'set_Detail_Register_header'
        ]),
        handleGetHeaderData (obj) {
            // console.log(obj)
            let headerData = {
                label: obj.act_label_id,
                content: '还没弄活动简介',
                imgurl: obj.actcoverimage,
                title: obj.acttitle,
                address: obj.address,
                addressDetail: obj.addressDetail,
                starttime: obj.starttime,
                endtime: obj.endtime,
                product: obj.product,
                actid: obj.id
            }
            this.headerData = headerData
            this.set_Detail_Register_header(headerData)
            // this.headerData = obj
        }
    },
    beforeRouteLeave (to, from, next) {
        this.change_Detail_MaskerType()
        next()
    }
}
</script>

<style lang="stylus" scoped>

</style>